package marking.liu.config;

import marking.liu.properties.StockInfoProperties;
import marking.liu.utils.IdWorkerUtil;
import marking.liu.utils.ParserStockInfoUtil;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;

@Configuration
@EnableConfigurationProperties({StockInfoProperties.class})
public class CommonConfig {

    /**
     * 密码加密器
     * BCryptPasswordEncoder方法采用SHA-256对密码进行加密
     * @return
     */
    @Bean
    public PasswordEncoder passwordEncoder() {
        return new BCryptPasswordEncoder();
    }

    /**
     * 唯一id生成器
     */
    @Bean
    public IdWorkerUtil idWorker() {
        return new IdWorkerUtil(1l, 2L);
    }

    /**
     * 定义解析股票各类信息的解析器
     * @param idWorkerUtil
     * @return
     */
    @Bean
    public ParserStockInfoUtil parserStockInfoUtil(IdWorkerUtil idWorkerUtil) {
        return new ParserStockInfoUtil(idWorkerUtil);
    }

}
